package com.bwf.servlet;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @Version v1.0
 * @Description: TODO
 * @Author ZHANZHONGXIN
 * @Date 2022/6/13 16:04
 * @Copyright 博为峰
 */
@WebServlet(urlPatterns = "/login")
public class LoginServlet extends BaseServlet {
    public String login(HttpServletRequest request, HttpServletResponse response) {
//        request.getHeader("Set-Cookie");
        String email = request.getParameter("email");
        String password = request.getParameter("password");
//        ServeletContext
        if (email.equals("zhangsan@163.com") && password.equals("123")) {
            HttpSession session = request.getSession();
            session.setAttribute("email", "zhangsan@163.com");
            return "forward:/main.jsp";
        } else {
            return "redirect:/index.jsp";
        }
    }

    public String logout(HttpServletRequest request, HttpServletResponse response) {
        HttpSession session = request.getSession();
        session.invalidate();
        return "redirect:/index.jsp";
    }
}
